#define  _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
  struct Node 
  {
     int val;
     struct Node *next;
     struct Node *random;
  };
 
  struct Node* copyRandomList(struct Node* head) {
      if (head == NULL)
          return NULL;
      struct Node* p1 = head;
      struct Node* phead = (struct Node*)malloc(sizeof(struct Node));
      struct Node* p2 = phead;
      while (p1)
      {
          struct Node* tmp = p1->next;
          p2->val = p1->val;
          p1->next = p2;
          p2->random = p1->random;
          p2->next = (struct Node*)malloc(sizeof(struct Node));
          if (tmp)
              p2 = p2->next;
          else
              p2->next = NULL;
          p1 = tmp;
      }
      p2 = phead;
      while (p2)
      {
          if (p2->random)
              p2->random = p2->random->next;
          p2 = p2->next;
      }
      return phead;
  }